$.fn.galleriffic   F
last analyzed

Complexity

Conditions 16
Paths > 20000

Size

Total Lines 504

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
nc 57344
nop 2
dl 0
loc 504
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like $.fn.galleriffic often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/*
2
 * jQuery Galleriffic plugin
3
 *
4
 * Copyright (c) 2008 Trent Foley (http://trentacular.com)
5
 * Licensed under the MIT License:
6
 *   http://www.opensource.org/licenses/mit-license.php
7
 *
8
 * Thanks to Taku Sano (Mikage Sawatari), whose history plugin I adapted to work with Galleriffic
9
 * Modified by Ghismo (ghismo.com) to disable the location rewrite 
10
 */
11
;(function($) {
12
13
	// Write noscript style
14
	document.write("<style type='text/css'>.noscript{display:none}</style>");
15
16
	var ver = 'galleriffic-1.0';
17
	var galleryOffset = 0;
18
	var galleries = [];
19
	var allImages = [];	
0 ignored issues
show
Unused Code introduced by
The variable allImages seems to be never used. Consider removing it.
Loading history...
20
	var historyCurrentHash;
21
	var historyBackStack;
22
	var historyForwardStack;
23
	var isFirst = false;
24
	var dontCheck = false;
25
	var isInitialized = false;
26
27
	function getHashFromString(hash) {
28
		if (!hash) return -1;
29
		hash = hash.replace(/^.*#/, '');
30
		if (isNaN(hash)) return -1;
31
		return (+hash);
32
	}
33
34
	function getHash() {
35
		var hash = location.hash;
36
		return getHashFromString(hash);
37
	}
38
39
	function registerGallery(gallery) {
40
		galleries.push(gallery);
41
42
		// update the global offset value
43
		galleryOffset += gallery.data.length;
44
	}
45
46
	function getGallery(hash) {
47
		for (i = 0; i < galleries.length; i++) {
0 ignored issues
show
Bug introduced by
The variable i seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.i.
Loading history...
48
			var gallery = galleries[i];
49
			if (hash < (gallery.data.length+gallery.offset))
50
				return gallery;
51
		}
52
		return 0;
53
	}
54
	
55
	function getIndex(gallery, hash) {
56
		return hash-gallery.offset;
57
	}
58
	
59
	function clickHandler(e, gallery, link) {
60
		gallery.pause();
61
62
		if (!gallery.settings.enableHistory) {
63
			var hash = getHashFromString(link.href);
64
			if (hash >= 0) {
65
				var index = getIndex(gallery, hash);
66
				if (index >= 0)
67
					gallery.goto(index);
68
			}
69
			e.preventDefault();
70
		}
71
	}
72
73
	function historyCallback() {
74
		// Using present location.hash always (seems to work, unlike the hash argument passed to this callback)
75
		var hash = getHash();
76
		if (hash < 0) return;
77
78
		var gallery = getGallery(hash);
79
		if (!gallery) return;
80
		
81
		var index = hash-gallery.offset;
82
		gallery.goto(index);
83
	}
84
	
85
	function historyInit() {
86
		if (isInitialized) return;
87
		isInitialized = true; 
88
89
		var current_hash = location.hash; //(enableHistory) ? location.hash : currentIndexHash; // Ghismo
90
91
		historyCurrentHash = current_hash;
92
		if ($.browser.msie) {
93
			// To stop the callback firing twice during initilization if no hash present
94
			if (historyCurrentHash == '') {
95
				historyCurrentHash = '#';
96
			}
97
		} else if ($.browser.safari) {
98
			// etablish back/forward stacks
99
			historyBackStack = [];
100
			historyBackStack.length = history.length;
0 ignored issues
show
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
101
			historyForwardStack = [];
102
			isFirst = true;
103
		}
104
105
		setInterval(function() { historyCheck(); }, 100);
106
	}
107
	
108
	function historyAddHistory(hash) {
0 ignored issues
show
introduced by
The function historyAddHistory does not seem to be used and can be removed.
Loading history...
109
		// This makes the looping function do something
110
		historyBackStack.push(hash);
111
		historyForwardStack.length = 0; // clear forwardStack (true click occured)
112
		isFirst = true;
113
	}
114
	
115
	function historyCheck() {
116
		if ($.browser.safari) {
117
			if (!dontCheck) {
118
				var historyDelta = history.length - historyBackStack.length;
0 ignored issues
show
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
119
				
120
				if (historyDelta) { // back or forward button has been pushed
121
					isFirst = false;
122
					if (historyDelta < 0) { // back button has been pushed
123
						// move items to forward stack
124
						for (var i = 0; i < Math.abs(historyDelta); i++) historyForwardStack.unshift(historyBackStack.pop());
125
					} else { // forward button has been pushed
126
						// move items to back stack
127
						for (var i = 0; i < historyDelta; i++) historyBackStack.push(historyForwardStack.shift());
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 124. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
128
					}
129
					var cachedHash = historyBackStack[historyBackStack.length - 1];
130
					if (cachedHash != undefined) {
131
						historyCurrentHash = location.hash; // (enableHistory) ? location.hash : currentIndexHash; // Ghismo
132
						historyCallback();
133
					}
134
				} else if (historyBackStack[historyBackStack.length - 1] == undefined && !isFirst) {
135
					historyCallback();
136
					isFirst = true;
137
				}
138
			}
139
		} else {
140
			// otherwise, check for location.hash
141
			var current_hash = location.hash; // (enableHistory) ? location.hash : currentIndexHash; // Ghismo
142
			if(current_hash != historyCurrentHash) {
143
				historyCurrentHash = current_hash;
144
				historyCallback();
145
			}
146
		}
147
	}
148
149
	var defaults = {
150
		delay:                  3000,
151
		numThumbs:              20,
152
		preloadAhead:           40, // Set to -1 to preload all images
153
		enableTopPager:         false,
154
		enableBottomPager:      true,
155
		imageContainerSel:      '',
156
		captionContainerSel:    '',
157
		controlsContainerSel:   '',
158
		loadingContainerSel:    '',
159
		renderSSControls:       true,
160
		renderNavControls:      true,
161
		playLinkText:           'Play',
162
		pauseLinkText:          'Pause',
163
		prevLinkText:           'Previous',
164
		nextLinkText:           'Next',
165
		nextPageLinkText:       'Next &rsaquo;',
166
		prevPageLinkText:       '&lsaquo; Prev',
167
		enableHistory:          false,
168
		autoStart:              false,
169
		onChange:               undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
170
		onTransitionOut:        undefined, // accepts a delegate like such: function(callback) { ... }
171
		onTransitionIn:         undefined, // accepts a delegate like such: function() { ... }
172
		onPageTransitionOut:    undefined, // accepts a delegate like such: function(callback) { ... }
173
		onPageTransitionIn:     undefined  // accepts a delegate like such: function() { ... }
174
	};
175
176
	$.fn.galleriffic = function(thumbsContainerSel, settings) {
177
		//  Extend Gallery Object
178
		$.extend(this, {
179
			ver: function() {
180
				return ver;
181
			},
182
183
			initializeThumbs: function() {
184
				this.data = [];
185
				var gallery = this;
186
				
187
				this.$thumbsContainer.find('ul.thumbs > li').each(function(i) {
188
					var $li = $(this);
189
					var $aThumb = $li.find('a.thumb');
190
					var hash = gallery.offset+i;
191
192
					gallery.data.push({
193
						title:$aThumb.attr('title'),
194
						slideUrl:$aThumb.attr('href'),
195
						caption:$li.find('.caption').remove(),
196
						hash:hash
197
					});
198
199
					// Setup history
200
					$aThumb.attr('rel', 'history');
201
					$aThumb.attr('href', '#'+hash);
202
					$aThumb.click(function(e) {
203
						clickHandler(e, gallery, this);
204
					});
205
				});
206
				return this;
207
			},
208
209
			isPreloadComplete: false,
210
211
			preloadInit: function() {
212
				if (this.settings.preloadAhead == 0) return this;
213
				
214
				this.preloadStartIndex = this.currentIndex;
215
				var nextIndex = this.getNextIndex(this.preloadStartIndex);
216
				return this.preloadRecursive(this.preloadStartIndex, nextIndex);
217
			},
218
			
219
			preloadRelocate: function(index) {
220
				// By changing this startIndex, the current preload script will restart
221
				this.preloadStartIndex = index;
222
				return this;
223
			},
224
225
			preloadRecursive: function(startIndex, currentIndex) {
226
				// Check if startIndex has been relocated
227
				if (startIndex != this.preloadStartIndex) {
228
					var nextIndex = this.getNextIndex(this.preloadStartIndex);
229
					return this.preloadRecursive(this.preloadStartIndex, nextIndex);
230
				}
231
232
				var gallery = this;
233
234
				// Now check for preloadAhead count
235
				var preloadCount = currentIndex - startIndex;
236
				if (preloadCount < 0)
237
					preloadCount = this.data.length-1-startIndex+currentIndex;
238
				if (this.settings.preloadAhead >= 0 && preloadCount > this.settings.preloadAhead) {
239
					// Do this in order to keep checking for relocated start index
240
					setTimeout(function() { gallery.preloadRecursive(startIndex, currentIndex); }, 500);
241
					return this;
242
				}
243
244
				var imageData = this.data[currentIndex];
245
				if (!imageData)
246
					return this;
247
248
				// If already loaded, continue
249
				if (imageData.image)
250
					return this.preloadNext(startIndex, currentIndex); 
251
				
252
				// Preload the image
253
				var image = new Image();
0 ignored issues
show
Bug introduced by
The variable Image seems to be never declared. If this is a global, consider adding a /** global: Image */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
254
				
255
				image.onload = function() {
256
					imageData.image = this;
257
					gallery.preloadNext(startIndex, currentIndex);
258
				};
259
260
				image.alt = imageData.title;
261
				image.src = imageData.slideUrl;
262
263
				return this;
264
			},
265
			
266
			preloadNext: function(startIndex, currentIndex) {
267
				var nextIndex = this.getNextIndex(currentIndex);
268
				if (nextIndex == startIndex) {
269
					this.isPreloadComplete = true;
270
				} else {
271
					// Use set timeout to free up thread
272
					var gallery = this;
273
					setTimeout(function() { gallery.preloadRecursive(startIndex, nextIndex); }, 100);
274
				}
275
				return this;
276
			},
277
278
			getNextIndex: function(index) {
279
				var nextIndex = index+1;
280
				if (nextIndex >= this.data.length)
281
					nextIndex = 0;
282
				return nextIndex;
283
			},
284
			
285
			getPrevIndex: function(index) {
286
				var prevIndex = index-1;
287
				if (prevIndex < 0)
288
					prevIndex = this.data.length-1;
289
				return prevIndex;
290
			},
291
292
			pause: function() {
293
				if (this.interval)
294
					this.toggleSlideshow();
295
				
296
				return this;
297
			},
298
299
			play: function() {
300
				if (!this.interval)
301
					this.toggleSlideshow();
302
				
303
				return this;
304
			},
305
306
			toggleSlideshow: function() {
307
				if (this.interval) {
308
					clearInterval(this.interval);
309
					this.interval = 0;
310
					
311
					if (this.$controlsContainer) {
312
						this.$controlsContainer
313
							.find('div.ss-controls a').removeClass().addClass('play')
314
							.attr('title', this.settings.playLinkText)
315
							.attr('href', '#play')
316
							.html(this.settings.playLinkText);
317
					}
318
				} else {
319
					this.ssAdvance();
320
321
					var gallery = this;
322
					this.interval = setInterval(function() {
323
						gallery.ssAdvance();
324
					}, this.settings.delay);
325
					
326
					if (this.$controlsContainer) {
327
						this.$controlsContainer
328
							.find('div.ss-controls a').removeClass().addClass('pause')
329
							.attr('title', this.settings.pauseLinkText)
330
							.attr('href', '#pause')
331
							.html(this.settings.pauseLinkText);
332
					}
333
				}
334
335
				return this;
336
			},
337
338
			ssAdvance: function() {
339
				var nextIndex = this.getNextIndex(this.currentIndex);
340
				var nextHash = this.data[nextIndex].hash;
341
342
				// Seems to be working on both FF and Safari
343
				if (this.settings.enableHistory)
344
					location.href = '#'+nextHash;
345
				else
346
					this.goto(nextIndex);
347
348
				// IE we need to explicity call goto
349
				//if ($.browser.msie) {
350
				//	this.goto(nextIndex);
351
				//}
352
353
				return this;
354
			},
355
356
			goto: function(index) {
357
				if (index < 0) index = 0;
358
				else if (index >= this.data.length) index = this.data.length-1;
359
				
360
				if (this.settings.onChange)
361
					this.settings.onChange(this.currentIndex, index);
362
				
363
				this.currentIndex = index;
364
				this.preloadRelocate(index);
365
				return this.refresh();
366
			},
367
			
368
			refresh: function() {
369
				var imageData = this.data[this.currentIndex];
370
				if (!imageData)
371
					return this;
372
				
373
				// Flag we are transitioning
374
				var isTransitioning = true;
375
376
				var gallery = this;
377
378
				var transitionOutCallback = function() {
379
					// Flag that the transition has completed
380
					isTransitioning = false;
381
382
					// Update Controls
383
					if (gallery.$controlsContainer) {
384
						gallery.$controlsContainer
385
							.find('div.nav-controls a.prev').attr('href', '#'+gallery.data[gallery.getPrevIndex(gallery.currentIndex)].hash).end()
386
							.find('div.nav-controls a.next').attr('href', '#'+gallery.data[gallery.getNextIndex(gallery.currentIndex)].hash);
387
					}
388
389
					var imageData = gallery.data[gallery.currentIndex];
390
391
					// Replace Caption
392
					if (gallery.$captionContainer) {
393
						gallery.$captionContainer.empty().append(imageData.caption);
394
					}
395
396
					if (imageData.image) {
397
						gallery.buildImage(imageData.image);
398
					} else {
399
						// Show loading container
400
						if (gallery.$loadingContainer) {
401
							gallery.$loadingContainer.show();
402
						}
403
					}
404
				}
405
406
				if (this.settings.onTransitionOut) {
407
					this.settings.onTransitionOut(transitionOutCallback);
408
				} else {
409
					this.$transitionContainers.hide();
410
					transitionOutCallback();
411
				}
412
413
				if (!imageData.image) {
414
					var image = new Image();
0 ignored issues
show
Bug introduced by
The variable Image seems to be never declared. If this is a global, consider adding a /** global: Image */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
415
					
416
					// Wire up mainImage onload event
417
					image.onload = function() {
418
						imageData.image = this;
419
420
						if (!isTransitioning) {
421
							gallery.buildImage(imageData.image);
422
						}
423
					};
424
425
					// set alt and src
426
					image.alt = imageData.title;
427
					image.src = imageData.slideUrl;
428
				}
429
430
				// This causes the preloader (if still running) to relocate out from the currentIndex
431
				this.relocatePreload = true;
432
433
				return this.syncThumbs();
434
			},
435
			
436
			buildImage: function(image) {
437
				if (this.$imageContainer) {
438
					this.$imageContainer.empty();
439
440
					var gallery = this;
441
					var nextIndex = this.getNextIndex(this.currentIndex);
442
443
					// Hide the loading conatiner
444
					if (this.$loadingContainer) {
445
						this.$loadingContainer.hide();
446
					}
447
448
					// Setup image
449
					this.$imageContainer
450
						.append('<span class="image-wrapper"><a class="advance-link" rel="history" href="#'+this.data[nextIndex].hash+'" title="'+image.alt+'"></a></span>')
451
						.find('a')
452
						.append(image)
453
						.click(function(e) {
454
							clickHandler(e, gallery, this);
455
						});
456
				}
457
458
				if (this.settings.onTransitionIn)
459
					this.settings.onTransitionIn();
460
				else
461
					this.$transitionContainers.show();
462
463
				return this;
464
			},
465
466
			syncThumbs: function() {
467
				if (this.$thumbsContainer) {
468
					var page = Math.floor(this.currentIndex / this.settings.numThumbs);
469
					if (page != this.currentPage) {
470
						this.currentPage = page;
471
						this.updateThumbs();
472
					}
473
474
					// Remove existing selected class and add selected class to new thumb
475
					var $thumbs = this.$thumbsContainer.find('ul.thumbs').children();
476
					$thumbs.filter('.selected').removeClass('selected');
477
					$thumbs.eq(this.currentIndex).addClass('selected');
478
				}
479
480
				return this;
481
			},
482
483
			updateThumbs: function() {
484
				var gallery = this;
485
				var transitionOutCallback = function() {
486
					gallery.rebuildThumbs();
487
488
					// Transition In the thumbsContainer
489
					if (gallery.settings.onPageTransitionIn)
490
						gallery.settings.onPageTransitionIn();
491
					else
492
						gallery.$thumbsContainer.show();
493
				};
494
495
				// Transition Out the thumbsContainer
496
				if (this.settings.onPageTransitionOut) {
497
					this.settings.onPageTransitionOut(transitionOutCallback);
498
				} else {
499
					this.$thumbsContainer.hide();
500
					transitionOutCallback();
501
				}
502
503
				return this;
504
			},
505
506
			rebuildThumbs: function() {
507
				// Initialize currentPage to first page
508
				if (this.currentPage < 0)
509
					this.currentPage = 0;
510
				
511
				var needsPagination = this.data.length > this.settings.numThumbs;
512
513
				// Rebuild top pager
514
				var $topPager = this.$thumbsContainer.find('div.top');
515
				if ($topPager.length == 0)
516
					$topPager = this.$thumbsContainer.prepend('<div class="top pagination"></div>').find('div.top');
517
518
				if (needsPagination && this.settings.enableTopPager) {
519
					$topPager.empty();
520
					this.buildPager($topPager);
521
				}
522
523
				// Rebuild bottom pager
524
				if (needsPagination && this.settings.enableBottomPager) {
525
					var $bottomPager = this.$thumbsContainer.find('div.bottom');
526
					if ($bottomPager.length == 0)
527
						$bottomPager = this.$thumbsContainer.append('<div class="bottom pagination"></div>').find('div.bottom');
528
					else
529
						$bottomPager.empty();
530
531
					this.buildPager($bottomPager);
532
				}
533
534
				var startIndex = this.currentPage*this.settings.numThumbs;
535
				var stopIndex = startIndex+this.settings.numThumbs-1;
536
				if (stopIndex >= this.data.length)
537
					stopIndex = this.data.length-1;
538
539
				// Show/Hide thumbs
540
				var $thumbsUl = this.$thumbsContainer.find('ul.thumbs');
541
				$thumbsUl.find('li').each(function(i) {
542
					var $li = $(this);
543
					if (i >= startIndex && i <= stopIndex) {
544
						$li.show();
545
					} else {
546
						$li.hide();
547
					}
548
				});
549
550
				// Remove the noscript class from the thumbs container ul
551
				$thumbsUl.removeClass('noscript');
552
				
553
				return this;
554
			},
555
556
			buildPager: function(pager) {
557
				var gallery = this;
558
				var startIndex = this.currentPage*this.settings.numThumbs;
559
				
560
				// Prev Page Link
561
				if (this.currentPage > 0) {
562
					var prevPage = startIndex - this.settings.numThumbs;
563
					pager.append('<a rel="history" href="#'+this.data[prevPage].hash+'" title="'+this.settings.prevPageLinkText+'">'+this.settings.prevPageLinkText+'</a>');
564
				}
565
566
				// Page Index Links
567
				for (i=this.currentPage-3; i<=this.currentPage+3; i++) {
0 ignored issues
show
Bug introduced by
The variable i seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.i.
Loading history...
568
					var pageNum = i+1;
569
					
570
					if (i == this.currentPage)
571
						pager.append('<span class="current">'+pageNum+'</span>');
572
					else if (i>=0 && i<this.numPages) {
573
						var imageIndex = i*this.settings.numThumbs;
574
						pager.append('<a rel="history" href="#'+this.data[imageIndex].hash+'" title="'+pageNum+'">'+pageNum+'</a>');
575
					}
576
				}
577
578
				// Next Page Link
579
				var nextPage = startIndex+this.settings.numThumbs;
580
				if (nextPage < this.data.length) {
581
					pager.append('<a rel="history" href="#'+this.data[nextPage].hash+'" title="'+this.settings.nextPageLinkText+'">'+this.settings.nextPageLinkText+'</a>');
582
				}
583
584
				pager.find('a').click(function(e) {
585
					clickHandler(e, gallery, this);
586
				});
587
588
				return this;
589
			}
590
		});
591
592
		// Now initialize the gallery
593
		this.settings = $.extend({}, defaults, settings);
594
		//enableHistory = this.settings.enableHistory; // Ghismo
595
596
		if (this.interval)
597
			clearInterval(this.interval);
598
599
		this.interval = 0;
600
		
601
		if (this.settings.imageContainerSel) this.$imageContainer = $(this.settings.imageContainerSel);
602
		if (this.settings.captionContainerSel) this.$captionContainer = $(this.settings.captionContainerSel);
603
		if (this.settings.loadingContainerSel) this.$loadingContainer = $(this.settings.loadingContainerSel);
604
605
		// Setup the jQuery object holding each container that will be transitioned
606
		this.$transitionContainers = $([]);
607
		if (this.$imageContainer)
608
			this.$transitionContainers = this.$transitionContainers.add(this.$imageContainer);
609
		if (this.$captionContainer)
610
			this.$transitionContainers = this.$transitionContainers.add(this.$captionContainer);
611
		
612
		// Set the hash index offset for this gallery
613
		this.offset = galleryOffset;
614
615
		this.$thumbsContainer = $(thumbsContainerSel);
616
		this.initializeThumbs();
617
618
		// Add this gallery to the global galleries array
619
		registerGallery(this);
620
621
		this.numPages = Math.ceil(this.data.length/this.settings.numThumbs);
622
		this.currentPage = -1;
623
		this.currentIndex = 0;
624
		var gallery = this;
625
626
		// Hide the loadingContainer
627
		if (this.$loadingContainer)
628
			this.$loadingContainer.hide();
629
630
		// Setup controls
631
		if (this.settings.controlsContainerSel) {
632
			this.$controlsContainer = $(this.settings.controlsContainerSel).empty();
633
			
634
			if (this.settings.renderSSControls) {
635
				if (this.settings.autoStart) {
636
					this.$controlsContainer
637
						.append('<div class="ss-controls"><a href="#pause" class="pause" title="'+this.settings.pauseLinkText+'">'+this.settings.pauseLinkText+'</a></div>');
638
				} else {
639
					this.$controlsContainer
640
						.append('<div class="ss-controls"><a href="#play" class="play" title="'+this.settings.playLinkText+'">'+this.settings.playLinkText+'</a></div>');
641
				}
642
643
				this.$controlsContainer.find('div.ss-controls a')
644
					.click(function(e) {
645
						gallery.toggleSlideshow();
646
						e.preventDefault();
647
						return false;
648
					});
649
			}
650
		
651
			if (this.settings.renderNavControls) {
652
				var $navControls = this.$controlsContainer
0 ignored issues
show
Unused Code introduced by
The variable $navControls seems to be never used. Consider removing it.
Loading history...
653
					.append('<div class="nav-controls"><a class="prev" rel="history" title="'+this.settings.prevLinkText+'">'+this.settings.prevLinkText+'</a><a class="next" rel="history" title="'+this.settings.nextLinkText+'">'+this.settings.nextLinkText+'</a></div>')
654
					.find('div.nav-controls a')
655
					.click(function(e) {
656
						clickHandler(e, gallery, this);
657
					});
658
			}
659
		}
660
661
		// Initialize history only once when the first gallery on the page is initialized
662
		historyInit();
663
		
664
		// Build image
665
		var hash = getHash();
666
		var hashGallery = (hash >= 0) ? getGallery(hash) : 0;
667
		var gotoIndex = (hashGallery && this == hashGallery) ? (hash-this.offset) : 0;
668
		this.goto(gotoIndex);
669
670
		if (this.settings.autoStart) {
671
			
672
			setTimeout(function() { gallery.play(); }, this.settings.delay);
673
		}
674
675
		// Kickoff Image Preloader after 1 second
676
		setTimeout(function() { gallery.preloadInit(); }, 1000);
677
678
		return this;
679
	};
680
})(jQuery);